package tang.client;

import tang.common.OpCode;
import tang.common.Packet;
import tang.common.CreateRequest;
import tang.common.CreateResponse;

/**
 * @author Tang
 * @classname Zookeeper
 * @description [ zk client ]
 * @date 2021/2/23 21:29
 */
public class Zookeeper {

    private ClientCnxn clientCnxn;

    Zookeeper(ClientCnxn clientCnxn) {
        this.clientCnxn = clientCnxn;
    }

    /**
     * 连接的状态
     */
    public enum States {

        CONNECTING, CONNECTED, CLOSE, NOT_CONNECTED;

        public boolean isAlive() {
            return this != CLOSE;
        }

        public boolean isConnected() {
            return this == CONNECTED;
        }

    }

    public String create(String path) {
        Packet packet = new Packet();
        packet.setType(OpCode.Create);
        packet.request = new CreateRequest("create",path);
        CreateResponse createResponse = new CreateResponse();
        packet.response = createResponse;
        clientCnxn.submitQueue(packet);
        System.out.println("收到服务器的结果数据是:" + createResponse.getResult());
        return path;
    }

}